package com.lj.syn.test;

import com.lj.syn.thread.*;

/**
 * 不同加锁方式测试：默认锁
 * synchroniezed在方法时，是否是整个对象加锁
 * 以及锁对像是谁
 * Created by yangsp1 on 16/3/27.
 */
public class SynSynchroniezedThis extends AbstractSyn {
    public synchronized void aa() throws InterruptedException {
        for(int i = 0; i < 3; i++) {
            Thread.sleep(1000);
            System.out.println("我是aa");
        }

    }
    public synchronized void bb() throws InterruptedException {
        for(int i = 0; i < 3; i++) {
           Thread.sleep(1000);
            System.out.println("我是bb");
        }

    }
    public void dd() throws InterruptedException {
        synchronized (this) {
            for (int i = 0; i < 3; i++) {
                Thread.sleep(1000);
                System.out.println("我是dd");
            }
        }
    }
    public void ee() throws InterruptedException {
        for (int i = 0; i < 3; i++) {
            Thread.sleep(2000);
            System.out.println("我是ee");
        }
    }


    public static void main(String args[]){
        AbstractSyn synTest = new SynSynchroniezedThis();
        Thread tA = new Thread(new ThreadTestAA(synTest));
        Thread tB = new Thread(new ThreadTestBB(synTest));
        Thread tD = new Thread(new ThreadTestDD(synTest));
        Thread tE = new Thread(new ThreadTestEE(synTest));
        tA.start();
        //tB.start();
        tD.start();
        //tE.start();
    }
}
